<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('多选地址信息')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">

        <form class="form-horizontal m" id="form-address-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">地址选择：</label>
                <div class="col-sm-8">
                    <label class="check-box">
                        <input type="checkbox" value="1">展开/折叠</label>
                    <label class="check-box">
                        <input type="checkbox" value="2">全选/全不选</label>
                    <label class="check-box">
                        <input type="checkbox" value="3">父子联动</label>
<!--                    <label class="check-box">-->
<!--                        <input type="checkbox" value="4">父子不联动</label>-->
                    <div id="addressTrees" class="ztree ztree-border"></div>
                </div>
            </div>
        </form>

    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">

        $(function() {
            var url = ctx + "system/address/treeData";
            var options = {
                id: "addressTrees",
                url: url,
                check: { enable: true },
                expandLevel: 0
            };
            $.tree.init(options);
        });

        $('input').on('ifChanged', function(obj){
            var type = $(this).val();
            var checked = obj.currentTarget.checked;
            if (type == 1) {
                if (checked) {
                    $._tree.expandAll(true);
                } else {
                    $._tree.expandAll(false);
                }
            } else if (type == "2") {
                if (checked) {
                    $._tree.checkAllNodes(true);
                } else {
                    $._tree.checkAllNodes(false);
                }
            } else if (type == "3") {
                if (checked) {
                    $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                } else {
                    $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
                }
            }
            // else if (type == "4") {
            //     // if (checked) {
            //         $._tree.setting.check.chkboxType = { "Y": "", "N": "ps" };
            //     // } else {
            //     //     $._tree.setting.check.chkboxType = { "Y": "ps", "N": "" };
            //     // }
            // }
        })

        /**
         * chkboxType: { “Y”: “ps”, “N”: “ps” }
         * Y 属性定义 checkbox 被勾选后的情况；
         * N 属性定义 checkbox 取消勾选后的情况；
         * “p” 表示操作会影响父级节点；
         * “s” 表示操作会影响子级节点。
         */

        function submitHandler() {
            let checkedNodes = $.tree.getCheckedNodes();
            alert(checkedNodes)
        }

    </script>
</body>
</html>